<?php

namespace App\Http\Requests\System\Config;

use App\Models\System\Config;
use Illuminate\Foundation\Http\FormRequest;

class UpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * 通过查询数据库来验证数据的规则
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        $list = Config::query()->get();

        return $list->keyBy('name')->map(function ($item) {
            return $item->rules;
        })->toArray();
    }
}
